package com.yuandian.ops.workbench.controller;

import com.yuandian.bpm.common.core.util.R;
import com.yuandian.ops.workbench.po.RealTimeAlarmParams;
import com.yuandian.ops.workbench.service.IRealTimeAlarmService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  实时告警Controller
 * <p>
 *
 * @author linshihe
 * @date 2021/10/25
 * @since 1.0.0
 */
@RestController
@RequestMapping("/ywgzt/realTimeAlarm")
@Api(tags = "业务告警-Controller")
public class OpsAlarmController {

    @Autowired
    private IRealTimeAlarmService realTimeAlarmService;


    /**
     * 获取告警详情列表
     * @param params 请求参数
     * @return
     */
    @PostMapping("/getRealTimeAlarmDetailList")
    public R<Object> getRealTimeAlarmDetailList(@RequestBody RealTimeAlarmParams params){

        return R.ok(realTimeAlarmService.getRealTimeAlarmDetailList(params));
    }

    /**
     * 导出告警详情列表
     * @param params 请求参数
     * @return
     */
    @PostMapping("/getRealTimeAlarmDetailListExport")
    public void getRealTimeAlarmDetailListExport(@RequestBody RealTimeAlarmParams params, HttpServletResponse response){
        params.setPageNum(1);
        //由于mybatis-plus 分页查询限制 500 条,小于0 如 -1 不受限制
        params.setPageSize(-1);
        try {
            realTimeAlarmService.getRealTimeAlarmDetailListExport(params, response);
         } catch (Exception e) {
//            ResponseUtil.setResponseResult(Result
//                    .setFail(ApiResultCode.EXPORT_EXCEL_ERROR.getCode(), ApiResultCode.EXPORT_EXCEL_ERROR.getMsg()), response);
        }
    }

    /**
     * 查询业务告警数列表
     * @param params 请求参数
     * @return
     */
    @PostMapping("/getBusinessAlarmList")
    public R<Object> getBusinessAlarmList(@RequestBody RealTimeAlarmParams params){

        return realTimeAlarmService.getBusinessAlarmCountList(params);
    }

}
